View Javadoc

1   /*
2    * JBCS - A JBuilder Plugin for Checkstyle
3    *
4    * This program is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU General Public License
6    * as published by the Free Software Foundation; either version 2
7    * of the License, or (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program; if not, write to the Free Software
16   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17   *
18   * Copyright © 2003
19   * Henri Tremblay
20   */
21  package com.henri.jbcs.gui;
22  
23  
24  import java.util.ArrayList;
25  import java.util.Collection;
26  import java.util.Iterator;
27  import java.util.StringTokenizer;
28  
29  import java.awt.BorderLayout;
30  import java.awt.Color;
31  import java.awt.GridBagConstraints;
32  import java.awt.GridBagLayout;
33  import java.awt.GridLayout;
34  import java.awt.Insets;
35  import javax.swing.BorderFactory;
36  import javax.swing.JCheckBox;
37  import javax.swing.JLabel;
38  import javax.swing.JPanel;
39  import javax.swing.JTextField;
40  import javax.swing.border.TitledBorder;
41  
42  import com.borland.jbcl.layout.VerticalFlowLayout;
43  import com.henri.jbcs.CSPreference;
44  import com.henri.jbcs.CheckStyleOpenTool;
45  import com.puppycrawl.tools.checkstyle.api.SeverityLevel;
46  
47  /***
48   * JBCS Property panel
49   * @author Henri Tremblay
50   * @version $Revision: 1.5 $ $Date: 2004/09/06 23:38:15 $
51   */
52  public class CSPropertyPagePanel extends JPanel
53  {
54     private CSPreference preference;
55  
56     privateng> JLabel packageFileLbl = new JLabel();
57     privateng> JTextField packageFileFld = new JTextField();
58     private JLabel checkstyleFileLbl = new JLabel();
59     private JTextField checkstyleFileFld = new JTextField();
60     private JLabel checkstylePropertyFileLbl = new JLabel();
61     private JPanel checkstylePropertyPanel = new JPanel();
62     private JTextField checkstylePropertyFileFld = new JTextField();
63     private GridBagLayout gridBagLayout2 = new GridBagLayout();
64     private JPanel jbcsPropertyPanel = new JPanel();
65     private JCheckBox showNoErrorChk = new JCheckBox();
66     private JCheckBox recusiveChk = new JCheckBox();
67     private JCheckBox clearMessagePaneChk = new JCheckBox();
68     private GridLayout gridLayout1 = new GridLayout();
69     private JPanel severityShownPanel = new JPanel();
70     private GridLayout gridLayout2 = new GridLayout();
71     private JCheckBox ignoreChk = new JCheckBox();
72     private JCheckBox infoChk = new JCheckBox();
73     private JCheckBox warningChk = new JCheckBox();
74     private JCheckBox errorChk = new JCheckBox();
75     private VerticalFlowLayout panelLayout = new VerticalFlowLayout();
76     private JPanel exclusionPathPanel = new JPanel();
77     private JTextField exclusionPathFld = new JTextField();
78     private BorderLayout borderLayout1 = new BorderLayout();
79  
80     public CSPropertyPagePanel() {
81        try {
82           jbInit();
83        }
84        catch(Exception e) {
85           e.printStackTrace();
86        }
87     }
88  
89     public CSPropertyPagePanel(CSPreference pref) {
90        this();
91        preference = pref;
92     }
93  
94     private void jbInit() throws Exception {
95        clearMessagePaneChk.setText("Clear Message Pane At Launch");
96        recusiveChk.setText("Package Recursive");
97        showNoErrorChk.setText("Show File Without Error");
98        packageFileLbl.setText("Package File:");
99        packageFileFld.setText("checkstyleFileFld");
100       checkstyleFileLbl.setText("Checkstyle File:");
101       checkstyleFileFld.setText("checkstyleFileFld");
102       checkstylePropertyFileLbl.setText("Checkstyle Property File:");
103       checkstylePropertyFileFld.setText("checkstylePropertyFileFld");
104       jbcsPropertyPanel.setLayout(gridLayout1);
105       gridLayout1.setColumns(2);
106       gridLayout1.setHgap(0);
107       gridLayout1.setRows(2);
108       checkstylePropertyPanel.setBorder(new TitledBorder(BorderFactory.createEtchedBorder(Color.white,new Color(148, 145, 140)),"Checkstyle Properties"));
109       jbcsPropertyPanel.setBorder(new TitledBorder(BorderFactory.createEtchedBorder(Color.white,new Color(148, 145, 140)),"JBCS Properties"));
110       severityShownPanel.setLayout(gridLayout2);
111       gridLayout2.setColumns(2);
112       gridLayout2.setRows(2);
113       severityShownPanel.setBorder(new TitledBorder(BorderFactory.createEtchedBorder(Color.white,new Color(148, 145, 140)),"Severity Shown"));
114       ignoreChk.setText("Ignore");
115       infoChk.setText("Info");
116       warningChk.setText("Warning");
117       errorChk.setText("Error");
118       this.setLayout(panelLayout);
119       exclusionPathPanel.setAlignmentY((float) 0.5);
120       exclusionPathPanel.setBorder(new TitledBorder(BorderFactory.createEtchedBorder(Color.white,new Color(148, 145, 140)),"Exclusion Path"));
121       exclusionPathPanel.setLayout(borderLayout1);
122       panelLayout.setHgap(2);
123       panelLayout.setVgap(2);
124       exclusionPathFld.setText("");
125       borderLayout1.setHgap(5);
126       borderLayout1.setVgap(5);
127       this.add(jbcsPropertyPanel, null);
128       jbcsPropertyPanel.add(showNoErrorChk, null);
129       jbcsPropertyPanel.add(recusiveChk, null);
130       jbcsPropertyPanel.add(clearMessagePaneChk, null);
131       checkstylePropertyPanel.setLayout(gridBagLayout2);
132       this.add(checkstylePropertyPanel, null);
133       checkstylePropertyPanel.add(checkstyleFileLbl,      new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
134             ,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));
135       checkstylePropertyPanel.add(packageFileLbl,     new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
136             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));
137       checkstylePropertyPanel.add(packageFileFld,     new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0
138             ,GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(2, 2, 2, 2), 0, 0));
139       checkstylePropertyPanel.add(checkstylePropertyFileLbl,      new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0
140             ,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));
141       checkstylePropertyPanel.add(checkstyleFileFld,     new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0
142             ,GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(2, 2, 2, 2), 0, 0));
143       checkstylePropertyPanel.add(checkstylePropertyFileFld,      new GridBagConstraints(1, 3, 1, 1, 1.0, 0.0
144             ,GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(2, 2, 2, 2), 0, 0));
145       this.add(severityShownPanel, null);
146       severityShownPanel.add(ignoreChk, null);
147       severityShownPanel.add(errorChk, null);
148       severityShownPanel.add(warningChk, null);
149       severityShownPanel.add(infoChk, null);
150       this.add(exclusionPathPanel, null);
151       exclusionPathPanel.add(exclusionPathFld, BorderLayout.CENTER);
152    }
153 
154    public void writeProperties() {
155       // Checkstyle prefs
156       preference.setConfigurationFile(checkstyleFileFld.getText());
157       preference.setPackageNameFile(packageFileFld.getText());
158       preference.setPropertiesFile(checkstylePropertyFileFld.getText());
159 
160       // JBCS prefs
161       preference.setShowNoError(showNoErrorChk.isSelected());
162       preference.setRecursive(recusiveChk.isSelected());
163       preference.setClearMessagePane(clearMessagePaneChk.isSelected());
164 
165       // Severities shown
166       preference.setSeverityShown(SeverityLevel.IGNORE, ignoreChk.isSelected());
167       preference.setSeverityShown(SeverityLevel.INFO, infoChk.isSelected());
168       preference.setSeverityShown(SeverityLevel.WARNING, warningChk.isSelected());
169       preference.setSeverityShown(SeverityLevel.ERROR, errorChk.isSelected());
170 
171       // Exlusion paths
172       String exclusionPathStr = exclusionPathFld.getText();
173       StringTokenizer st = new StringTokenizer(exclusionPathStr, ",");
174       Collection exclusionPath = new ArrayList();
175       while(st.hasMoreTokens()) {
176          exclusionPath.add(st.nextToken());
177       }
178       preference.setExlusionPath(exclusionPath);
179 
180       CheckStyleOpenTool.setPreference(preference);
181    }
182 
183    public void readProperties() {
184       // Checkstyle prefs
185       checkstyleFileFld.setText(preference.getConfigurationFile());
186       packageFileFld.setText(preference.getPackageNameFile());
187       checkstylePropertyFileFld.setText(preference.getPropertiesFile());
188 
189       // JBCS prefs
190       showNoErrorChk.setSelected(preference.getShowNoError());
191       recusiveChk.setSelected(preference.getRecursive());
192       clearMessagePaneChk.setSelected(preference.getClearMessagePane());
193 
194       // Severities shown
195       ignoreChk.setSelected(preference.isSeverityShown(SeverityLevel.IGNORE));
196       infoChk.setSelected(preference.isSeverityShown(SeverityLevel.INFO));
197       warningChk.setSelected(preference.isSeverityShown(SeverityLevel.WARNING));
198       errorChk.setSelected(preference.isSeverityShown(SeverityLevel.ERROR));
199 
200       // Exclusion paths
201       String exclusionPathStr = "";
202       Collection exclusionPath = preference.getExclusionPath();
203       for(Iterator it = exclusionPath.iterator(); it.hasNext();) {
204          String path = (String) it.next();
205          exclusionPathStr += path + ",";
206       }
207       exclusionPathFld.setText(exclusionPathStr
208          .endsWith(",") ? exclusionPathStr.substring(0, exclusionPathStr.length() - 1) : exclusionPathStr);
209    }
210 }
211